package com.tduck.cloud.form.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tduck.cloud.form.entity.UserFormEntity;
import com.tduck.cloud.form.mapper.UserFormMapper;
import com.tduck.cloud.form.service.UserFormService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 表单主表(Form)表服务实现类
 *
 * @author smalljop
 * @since 2020-11-18 18:16:18
 */
@Service
@RequiredArgsConstructor
public class UserFormServiceImpl extends ServiceImpl<UserFormMapper, UserFormEntity> implements UserFormService {

    private final UserFormMapper userFormMapper;

    @Override
    public UserFormEntity getByKey(final String key) {
        if (StrUtil.isBlank(key)) {
            return null;
        }
        UserFormEntity entity = this.getOne(Wrappers.<UserFormEntity>lambdaQuery().eq(UserFormEntity::getKey, key)
                            .eq(UserFormEntity::getDeleted,false));
        return entity;
    }

    @Override
    public Map<String,Integer> getTotalCount(String key, String hospitalCode, String beginDate, String endDate) {
        return userFormMapper.getTotalCount(key, hospitalCode, beginDate, endDate);
    }

    @Override
    public List<Map<String,Integer>> getDateCount(String hospitalCode, String beginDate, String endDate) {
        return userFormMapper.getDateCount(hospitalCode, beginDate, endDate);
    }
}